//
//  UIImageView+cache.m
//  iLookForiPhone
//
//  Created by Yinghui Zhang on 6/6/12.
//  Copyright (c) 2012 LavaTech. All rights reserved.
//

#import "BKImageView.h"
#import <AFNetworking/UIImageView+AFNetworking.h>

@interface BKImageView()
@property (nonatomic, assign) id target;
@property (nonatomic, assign) SEL action;
@end

@implementation BKImageView
@synthesize object;


- (void)setImageAndNotify:(UIImage *)image{    
    if (self.delegate && [self.delegate respondsToSelector:@selector(imageView:didChangeImage:)]) {
        if (image) {
            [self setImage:image];
        }
        [self.delegate imageView:self didChangeImage:image];
    }else{
        [self setImage:image];
    }
}
- (void)tapEvent:(UIGestureRecognizer *)r{
    if (self.target && self.action && r.state == UIGestureRecognizerStateEnded) {
//        [self.target performSelector:self.action withObject:self];
        IMP imp = [self.target methodForSelector:self.action];
        void (*func)(id, SEL, NSObject *) = (void *)imp;
        func(self.target, self.action, self);
    }
}
- (void)addTarget:(id)target action:(SEL)action{
    self.userInteractionEnabled = YES;
    self.target = target;
    self.action = action;
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapEvent:)];
    [self addGestureRecognizer:tap];
}
- (void)dealloc{
    //[super dealloc];
}
@end
